﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.XPath;
using System.ComponentModel.Composition;

namespace Kindler.Processors
{
    [Export(typeof(IProcessor))]
    public class HeadingSpacerProcessor : IProcessor
    {
        public void Process(XDocument htmlBook)
        {
            var headers = from XElement header in htmlBook.XPathSelectElements("descendant::h2|h3|h4|h4")
                          select header;

            // Add some space above and below all headings
            foreach (var header in headers)
            {
                header.AddBeforeSelf(new XElement("br"));
                header.AddAfterSelf(new XElement("br"));
            }
        }
    }
}
